﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using NewsletterCreator;

public partial class SendNewsLetter : System.Web.UI.UserControl
{
    NumberedNewsletterItem numItem;
    DatedNewsletterItem dateItem;

    protected void Page_Init(object sender, EventArgs e)
    {
        SendNewsletterEmail newsletterSender = new SendNewsletterEmail();

        String ID =  Request.QueryString["id"];
        ManageLibrary libManager = new ManageLibrary();
        Library lib = libManager.getLibrary(ID);
        int id = Convert.ToInt32(ID);
                
        NewsletterGenerator1.OrganizationName = lib.Name;

        numItem = new NumberedNewsletterItem();
        numItem.Title = "Announcements";
        numItem.Text = "Left";
        numItem.Datasource = newsletterSender.compileAnnouncements(id);

        NewsletterGenerator1.AddPanelControl(numItem, 0);

        dateItem = new DatedNewsletterItem();
        dateItem.Title = "Upcoming Events";
        dateItem.Text = "Right";
        dateItem.Datasource = newsletterSender.compileEvents(id);
        dateItem.DatasourceDateColumn = 2;

        NewsletterGenerator1.AddPanelControl(dateItem, 1);

    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSendNewsletter_Click(object sender, EventArgs e)
    {
        String newsletterText = NewsletterGenerator1.generateHTML();

        SendNewsletterEmail sendManager = new SendNewsletterEmail();
        sendManager.sendNewsletter(newsletterText, Convert.ToInt32(Request.QueryString["id"]));
    }
}
